using MediatR;
using Warehouse.API.APP.Commands;
using Warehouse.Dto;
using Warehouse.Services.IServices;

namespace Warehouse.API.APP.Handlers
{
    /// <summary>
    /// 创建调拨单命令处理器
    /// </summary>
    public class CreateAllocationHandler : IRequestHandler<CreateAllocationCommand, CreateAllocationResponse>
    {
        private readonly IAllocationService _allocationService;

        public CreateAllocationHandler(IAllocationService allocationService)
        {
            _allocationService = allocationService;
        }

        public async Task<CreateAllocationResponse> Handle(CreateAllocationCommand request, CancellationToken cancellationToken)
        {
            var createRequest = new CreateAllocationRequest
            {
                TransferType = request.TransferType,
                ApplyDate = request.ApplyDate,
                FromWarehouseId = request.FromWarehouseId,
                ToWarehouseId = request.ToWarehouseId,
                HandlerName = request.HandlerName,
                ApplicantName = request.ApplicantName,
                Remark = request.Remark,
                SkipValidation = request.SkipValidation,
                Lines = request.Lines
            };

            return await _allocationService.CreateAllocationAsync(createRequest);
        }
    }
}

